package com.boil.qz.safekavass.model;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by ChenYong on 2017-04-11.
 * <br>
 * 后台用户实体类。
 */
@Entity
@Table(name = "TB_LOGIN_USERS")
public class LoginUser extends BaseEntity {
    /**
     * 序列化 ID
     */
    private static final long serialVersionUID = -1833106971749259308L;
    /**
     * 登录 ID
     */
    private String loginid;
    /**
     * 姓名
     */
    private String loginName;
    /**
     * 密码
     */
    private String pwd;
    /**
     * 所属行业代码
     */
    private String industryCode;
    /**
     * 是否管理员：0-普通用户；1-管理员；2-超级管理员（只有超级管理员才能发红包）
     */
    private String isAdmin;
    /**
     * 是否为领导：0-否；1-是
     */
    private String isLeader;
    /**
     * 所属企业编码
     */
    private String collieryNo;
    /**
     * 用户拥有的角色 <code>Set</code>
     */
    @ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.MERGE)
    @JoinTable(name = "TB_QZ_USER_ROLE", //
            joinColumns = @JoinColumn(name = "USER_ID"), //
            inverseJoinColumns = @JoinColumn(name = "ROLE_ID"))
    private Set<RoleEntity> roles;

    // 普通初始化块
    {
        roles = new HashSet<RoleEntity>();
    }

    /**
     * 默认构造器。
     */
    public LoginUser() {
        super();
    }

    public String getLoginid() {
        return loginid;
    }

    public void setLoginid(String loginid) {
        this.loginid = loginid;
    }

    public String getLoginName() {
        return loginName;
    }

    public void setLoginName(String loginName) {
        this.loginName = loginName;
    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    public String getIndustryCode() {
        return industryCode;
    }

    public void setIndustryCode(String industryCode) {
        this.industryCode = industryCode;
    }

    public String getIsAdmin() {
        return isAdmin;
    }

    public void setIsAdmin(String isAdmin) {
        this.isAdmin = isAdmin;
    }

    public String getIsLeader() {
        return isLeader;
    }

    public void setIsLeader(String isLeader) {
        this.isLeader = isLeader;
    }

    public String getCollieryNo() {
        return collieryNo;
    }

    public void setCollieryNo(String collieryNo) {
        this.collieryNo = collieryNo;
    }

    public Set<RoleEntity> getRoles() {
        return roles;
    }

    public void setRoles(Set<RoleEntity> roles) {
        this.roles = roles;
    }

    @Override
    public String toString() {
        final StringBuffer sb = new StringBuffer("LoginUser{");
        sb.append("loginid='").append(loginid).append('\'');
        sb.append(", loginName='").append(loginName).append('\'');
        sb.append(", pwd='").append(pwd).append('\'');
        sb.append(", industryCode='").append(industryCode).append('\'');
        sb.append(", isAdmin='").append(isAdmin).append('\'');
        sb.append(", isLeader='").append(isLeader).append('\'');
        sb.append(", collieryNo='").append(collieryNo).append('\'');
        sb.append(", roles=").append(roles);
        sb.append(", id=").append(id);
        sb.append('}');
        return sb.toString();
    }
}